
<template>
    <div class="threeJsPrc72">
      <div class="myCanvas" ref="myCanvas"></div>
    </div>
</template>

<script lang="ts">
import { Vue, Options } from 'vue-property-decorator';
import * as THREE from 'three';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
const scene = new THREE.Scene();
scene.add(new THREE.AxesHelper(250));
const camera = new THREE.PerspectiveCamera();
camera.fov = 70;
camera.near = 1;
camera.near = 10000;
const renderer = new THREE.WebGLRenderer({
  alpha: true,
});
renderer.debug.checkShaderErrors = false;
renderer.setClearColor(0xb9d3ff, 1);

@Options({ components: {
} })
export default class ThreeJsPrc72 extends Vue {
  public rect: DOMRect|null=null;
  public dpr =750 / window.innerWidth;
  public controls!: OrbitControls;

  public mounted() {
    this.rect = (this.$el as HTMLElement).getBoundingClientRect();
    (this.$refs.myCanvas as HTMLDivElement).append(renderer.domElement);
    renderer.setPixelRatio(this.dpr);
    renderer.setSize(this.rect.width, this.rect.height, false);
    camera.aspect = this.rect.width / this.rect.height;
    camera.position.set(200, 100, 200);
    camera.lookAt(scene.position);
    renderer.render(scene, camera);

    // const geometry = new THREE.BoxGeometry();
    // const arc = new THREE.ArcCurve(0, 0, 100, 0, 2 * Math.PI, false);
    // const points = arc.getPoints(50);
    // geometry.setFromPoints(points);
    // const material = new THREE.LineBasicMaterial({
    //   color: 0x000000,
    // });
    // const line = new THREE.Line(geometry, material);
    // scene.add(line);

    const geometry = new THREE.BoxGeometry(); // 声明一个几何体对象Geometry
    console.log(geometry.attributes.position.array);
    const p1 = new THREE.Vector3(50, 0, 0); // 顶点1坐标
    const p2 = new THREE.Vector3(0, 70, 0); // 顶点2坐标
    // 顶点坐标添加到geometry对象

    const material = new THREE.LineBasicMaterial({
      color: 0xffff00,
    });// 材质对象
    // 线条模型对象
    const line = new THREE.Line(geometry, material);
    scene.add(line); // 线条对象添加到场景中


    renderer.setAnimationLoop(() => {
      renderer.render(scene, camera);
    });

    this.controls = new OrbitControls(camera, renderer.domElement);
  }
}
</script>

<style lang="postcss" scoped>
.threeJsPrc72{
  touch-action: none;
  width: 100%;
  height: 100%;
  background: grey;
}
</style>
